/*
 * @lc app=leetcode.cn id=1979 lang=javascript
 *
 * [1979] 找出数组的最大公约数
 */

// @lc code=start
const gcd = function (a, b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}

Math.minmax = function (nums) {
  let min = nums[0], max = nums[0];
  for (let i = 0; i < nums.length; i++) {
    min = Math.min(min, nums[i]);
    max = Math.max(max, nums[i])
  }
  return [min, max];
}

/**
 * @param {number[]} nums
 * @return {number}
 */
var findGCD = function (nums) {
  return gcd(...Math.minmax(nums));
};
// @lc code=end

